package com.docker.sys.user;

import com.docker.core.constant.APPIDConstant;
import com.docker.core.mvc.APPID;
import com.docker.core.mvc.Remark;
import com.docker.core.mvc.controller.BaseAPIController;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Okv;
import kit.docker.validator.ValidatorKit;

/**
 * @Author ldl
 * @Create 2020/09/17 017 09:54
 */
@Remark("系统用户")
@APPID(APPIDConstant.dum_web)
public class InsideUserController extends BaseAPIController {

    @Inject
    private InsideUserService insideUserService;

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/09/18 018 09:35
     */
    @Remark("用户分页列表")
    public void paginate() {
        Okv cond = Okv.create();
        String searchKey = getPara("search_key");
        if (ValidatorKit.validateClassName(searchKey, false)) {
            cond.set("ui.user_name = ", searchKey);
        } else if (ValidatorKit.validateMobile(searchKey, false)) {
            cond.set("ui.user_phone = ", searchKey);
        }
        renderAPISuccess(insideUserService.paginate(Okv.by("cond", cond), getPageNum(), getPageSize()));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/09/18 018 09:35
     */
    @Remark("新增用户")
    public void save() {
        renderAPI(insideUserService.save(getBean(InsideUserBean.class, ""), getUserId()));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/09/18 018 09:35
     */
    @Remark("修改用户")
    public void update() {
        renderAPI(insideUserService.update(getBean(InsideUserBean.class, ""), getUserId()));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/09/18 018 09:36
     */
    @Remark("启用用户")
    public void enable() {
        renderAPI(insideUserService.enable(getPara("user_id"), getUserId()));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/09/18 018 09:36
     */
    @Remark("停用用户")
    public void disable() {
        renderAPI(insideUserService.disable(getPara("user_id"), getUserId()));
    }

}
